// const baseUrl = 'http://hebi.xinguanghudong.com:9090'  
import Vue from "vue"
var vm = new Vue()
// import qs from '../components/qs/dist/qs.js'

const baseApiUrl = "https://bafang.wxqiandao.com/api" //正式

// import {
// 	baseApiUrl
// } from '@/utils/settings.js'

const baseUrl = baseApiUrl

// console.log(process.env.node);
//const baseUrl ='http://172.17.1.52:9091'

// const baseUrl = "http://api.test.degaocloud.cn"


//const baseUrl ='http://172.17.0.34:10000'
// import store from '@/store/index.js'
const request = (url = '', date = {}, type = 'GET', header = {
	'dg': uni.getStorageSync("sessionId"),
	"appVersion": "1.0.0",
	// #ifdef MP-WEIXIN
	"source": "xcx"
	// #endif

}) => {
	return new Promise((resolve, reject) => {
		// if(type=='post'){
		// 	// type = 'post',
		// 	header = {
		// 		"content-type": 'application/json',
		// 		//  'Cookie': 'JSESSIONID=' +  uni.getStorageSync("sessionId")||'',
		// 		// 'dg': uni.getStorageSync("sessionId"),
		// 		"appVersion": "1.0.0",
		// 		// #ifdef MP-WEIXIN
		// 		"source":"xcx"
		// 		// #endif
		// 	}
		// }else if (type != 'GET' && type != 'post') {
		// 	// date = qs.stringify(date)
		// 	header = {
		// 		"content-type": 'application/x-www-form-urlencoded',
		// 		//  'Cookie': 'JSESSIONID=' +  uni.getStorageSync("sessionId")||'',
		// 		// 'dg': uni.getStorageSync("sessionId"),
		// 		"appVersion": "1.0.0",
		// 		// #ifdef MP-WEIXIN
		// 		"source":"xcx"
		// 		// #endif
		// 	}
		// }
		header = {
			"content-type": 'application/x-www-form-urlencoded',
			// #ifdef MP-WEIXIN
			"source": "xcx"
			// #endif
		}
		// date.openid=uni.getStorageSync('openid');
		uni.request({
			method: type,
			url: baseUrl + url,
			data: date,
			xhrFields: {
				withCredentials: true
			},
			header

		}).then((response) => {
			let {
				data
			} = response;
			resolve(data.data);

		}).catch(error => {
			let [err, res] = error;
			reject(err)
		});
	})
}
export default request